import { config } from "../../utils/config";
import { request } from "../../utils/request";
import { ResponseData } from "../types";
import { VcardImageReq, VcardReq, VcardInfo, VcardJobList, VcardEduList } from "./types"

// 通讯录和分享名片API实现.
class VcardApiImpl {

  // 获取名片图像地址
  getVcardImage(req: VcardImageReq): string {
    if (req.vcardToken) {
      return config.baseUrl + "/v1/front/vcard/image/share/" + req.imageType + "/" + req.vcardToken;
    }
    return config.baseUrl + "/v1/front/vcard/image/key/" + req.imageType + "/" + req.vcardKey;
  }

  // 获取名片头像地址
  getVcardAvatar(req: VcardReq): string {
    if (req.vcardToken) {
      return config.baseUrl + "/v1/front/vcard/vcard_avatar/share/" + req.vcardToken;
    }
    return config.baseUrl + "/v1/front/vcard/vcard_avatar/key/" + req.vcardKey;
  }

  // 获取当前会话用户
  getVcardInfo(req: VcardReq): Promise<ResponseData<VcardInfo>> {
    let url = req.vcardToken ? "/v1/front/vcard/vcard_person/share/" + req.vcardToken :
      "/v1/front/vcard/vcard_person/key/" + req.vcardKey;
    return request({
      url: url,
      method: "GET"
    });
  }

  // 获取名片个人教育经历
  getVcardEduInfo(req: VcardReq): Promise<ResponseData<VcardEduList>> {
    let url = req.vcardToken ? "/v1/front/vcard/vcard_person_edu/list/share/" + req.vcardToken :
      "/v1/front/vcard/vcard_person_edu/list/key/" + req.vcardKey;
    return request({
      url: url,
      method: "GET"
    });
  }

  // 获取名片个人工作经历
  getVcardJobInfo(req: VcardReq): Promise<ResponseData<VcardJobList>> {
    let url = req.vcardToken ? "/v1/front/vcard/vcard_person_job/list/share/" + req.vcardToken :
      "/v1/front/vcard/vcard_person_job/list/key/" + req.vcardKey;
    return request({
      url: url,
      method: "GET"
    });
  }

}

const vcardApi = new VcardApiImpl();

export { vcardApi }
